<template>
  <div>
    <el-col :span="6">
      <div class="grid-content bg-purple">
        <el-input
          v-model="filterText"
          placeholder="输入关键字进行过滤"
        />

        <el-tree
          ref="tree"
          class="filter-tree"
          :data="dictData"
          :props="defaultProps"
          default-expand-all
          :filter-node-method="filterNode"
        />
      </div>
    </el-col>
    <el-col :span="18">
      <div class="grid-content bg-purple">2</div>
    </el-col>
  </div>
</template>

<script>
import {
  getDictAll
} from '@/api/dict'

export default {
  name: 'Index',

  data() {
    return {
      filterText: '',
      dictData: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      // 获取字典数据
      console.log('111111')
      this.getDictAllWeb()
    },
    getDictAllWeb() {
      getDictAll().then(res => {
        this.dictData = res.data
      })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    }
  }
}
</script>
<style>

</style>
